<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class ApkResources - RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
</script>

<script src="./js/jquery.js"></script>
<script src="./js/darkfish.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">



<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-get_all_keys">#get_all_keys</a>
    
    <li ><a href="#method-i-get_all_strings">#get_all_strings</a>
    
    <li ><a href="#method-i-get_all_types">#get_all_types</a>
    
    <li ><a href="#method-i-get_default_resource_value">#get_default_resource_value</a>
    
    <li ><a href="#method-i-get_resource_key">#get_resource_key</a>
    
    <li ><a href="#method-i-get_resource_value">#get_resource_value</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-ApkResources">
  <h1 id="class-ApkResources" class="class">
    class ApkResources
  </h1>

  <section class="description">
    
<p>Class to parse an APK&#39;s resources.arsc data and retrieve resource data
associated with a given R.id value</p>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="ChunkHeader">ChunkHeader
        
        <dd><p>Structure defining the type and size of each resource chunk</p>

<p><a href="ApkResources.html#ChunkHeader">ChunkHeader</a> = Struct.new(:type,
:size, :chunk_size)</p>
        
      
        <dt id="Package">Package
        
        <dd><p>Structure defining the resource contents for a package chunk</p>

<p><a href="ApkResources.html#Package">Package</a> = Struct.new(:header,
:stringpool_typestrings, :stringpool_keystrings, :type_data)</p>
<ul><li>
<p><code>package_header</code> = <a
href="ApkResources.html#PackageHeader">PackageHeader</a></p>
</li><li>
<p><code>stringpool_typestrings</code> = <a
href="ApkResources.html#StringPool">StringPool</a> containing all type
strings in the package</p>
</li><li>
<p><code>stringpool_keystrings</code> = <a
href="ApkResources.html#StringPool">StringPool</a> containing all key
strings in the package</p>
</li><li>
<p><code>type_data</code> = Array of <a
href="ApkResources.html#ResTypeSpec">ResTypeSpec</a> chunks in the package</p>
</li></ul>
        
      
        <dt id="PackageHeader">PackageHeader
        
        <dd><p>Structure defining the data inside of the package chunk</p>

<p><a href="ApkResources.html#PackageHeader">PackageHeader</a> =
Struct.new(:header, :id, :name, :type_strings, :key_strings)</p>
<ul><li>
<p><code>header</code> = <a
href="ApkResources.html#ChunkHeader">ChunkHeader</a></p>
</li><li>
<p><code>id</code> = <a href="ApkResources.html#Package">Package</a> id;
usually 0x7F for application resources</p>
</li><li>
<p><code>name</code> = <a href="ApkResources.html#Package">Package</a> name
(e.g. “com.example.application”)</p>
</li><li>
<p><code>type_strings</code> = Array of the type string values present (e.g.
“drawable”)</p>
</li><li>
<p><code>key_strings</code> = Array of the key string values present (e.g.
“ic_launcher”)</p>
</li></ul>
        
      
        <dt id="ResType">ResType
        
        <dd><p>Structure that houses all the resources for a given type</p>

<p><a href="ApkResources.html#ResType">ResType</a> = Struct.new(:header, :id,
:config, :entry_count, :entries)</p>
<ul><li>
<p><code>header</code> = <a
href="ApkResources.html#ChunkHeader">ChunkHeader</a></p>
</li><li>
<p><code>id</code> = String value of the referenced type (e.g. “drawable”)</p>
</li><li>
<p><code>config</code> = <a
href="ApkResources.html#ResTypeConfig">ResTypeConfig</a> defining the
configuration for this type</p>
</li><li>
<p><code>entry_count</code> = Number of entries in this chunk</p>
</li><li>
<p><code>entries</code> = Array of Hashes of [ResTypeConfig, ResTypeEntry] in
this chunk</p>
</li></ul>
        
      
        <dt id="ResTypeConfig">ResTypeConfig
        
        <dd><p>Structure that houses the configuration flags for a given resource.</p>

<p><a href="ApkResources.html#ResTypeConfig">ResTypeConfig</a> =
Struct.new(:imsi, :locale, :screen_type, :input, :screen_size, :version,
:screen_config, :screen_size_dp)</p>
<ul><li>
<p><code>imsi</code> = Flags marking country code and network code</p>
</li><li>
<p><code>locale</code> = Flags marking locale requirements (language)</p>
</li><li>
<p><code>screen_type</code> = Flags/values for screen density</p>
</li><li>
<p><code>input</code> = Flags marking input types and visibility status</p>
</li><li>
<p><code>screen_size</code> = Flags marking screen size and length</p>
</li><li>
<p><code>version</code> = Minimum API version</p>
</li><li>
<p><code>screen_config</code> = Flags marking screen configuration (like
orientation)</p>
</li><li>
<p><code>screen_size_dp</code> = Flags marking smallest width constraints</p>
</li></ul>

<p>A default configuration is defined as ResTypeConfig.new(0, 0, 0, 0, 0, 0,
0, 0)</p>
        
      
        <dt id="ResTypeEntry">ResTypeEntry
        
        <dd><p>Structure that houses the data for a given resource entry</p>

<p><a href="ApkResources.html#ResTypeEntry">ResTypeEntry</a> =
Struct.new(:flags, :key, :data_type, :data)</p>
<ul><li>
<p><code>flags</code> = Flags marking if the resource is complex or public</p>
</li><li>
<p><code>key</code> = Key string for the resource (e.g. “ic_launcher” of
R.drawable.ic_launcher“)</p>
</li><li>
<p><code>data_type</code> = Type identifier.  The meaning of this value varies
with the type of resource</p>
</li><li>
<p><code>data</code> = Resource value (e.g. “res/drawable/ic_launcher” for
R.drawable.ic_launcher“)</p>
</li></ul>

<p>A single resource key can have multiple entries depending on configuration,
so these structs are often returned in groups, keyed by a <a
href="ApkResources.html#ResTypeConfig">ResTypeConfig</a></p>
        
      
        <dt id="ResTypeSpec">ResTypeSpec
        
        <dd><p>Structure defining the flags for a block of common resources</p>

<p><a href="ApkResources.html#ResTypeSpec">ResTypeSpec</a> =
Struct.new(:header, :id, :entry_count, :entries, :types)</p>
<ul><li>
<p><code>header</code> = <a
href="ApkResources.html#ChunkHeader">ChunkHeader</a></p>
</li><li>
<p><code>id</code> = String value of the referenced type (e.g. “drawable”)</p>
</li><li>
<p><code>entry_count</code> = Number of type entries in this chunk</p>
</li><li>
<p><code>entries</code> = Array of config flags for each type entry</p>
</li><li>
<p><code>types</code> = The <a href="ApkResources.html#ResType">ResType</a>
associated with this spec</p>
</li></ul>
        
      
        <dt id="StringPool">StringPool
        
        <dd><p>Structure that houses a group of strings</p>

<p><a href="ApkResources.html#StringPool">StringPool</a> = Struct.new(:header,
:string_count, :style_count, :values)</p>
<ul><li>
<p><code>header</code> = <a
href="ApkResources.html#ChunkHeader">ChunkHeader</a></p>
</li><li>
<p><code>string_count</code> = Number of normal strings in the pool</p>
</li><li>
<p><code>style_count</code> = Number of styled strings in the pool</p>
</li><li>
<p><code>values</code> = Array of the string values</p>
</li></ul>
        
      
      </dl>
    </section>
    

    
    <section class="attribute-method-details" class="method-section">
      <header>
        <h3>Attributes</h3>
      </header>

      
      <div id="attribute-i-package_header" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">package_header</span><span
            class="attribute-access-type">[R]</span>
        </div>

        <div class="method-description">
        
        <p><a href="ApkResources.html#PackageHeader">PackageHeader</a> containing
information about all the type and key strings in the package</p>
        
        </div>
      </div>
      
      <div id="attribute-i-packages" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">packages</span><span
            class="attribute-access-type">[R]</span>
        </div>

        <div class="method-description">
        
        <p>Hash of <a href="ApkResources.html#Package">Package</a> chunks, keyed by
package id</p>
        
        </div>
      </div>
      
      <div id="attribute-i-stringpool_main" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">stringpool_main</span><span
            class="attribute-access-type">[R]</span>
        </div>

        <div class="method-description">
        
        <p><a href="ApkResources.html#StringPool">StringPool</a> containing all value
strings in the package</p>
        
        </div>
      </div>
      
    </section>
    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(apk_file)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Create a new <a href="ApkResources.html">ApkResources</a> instance from the
specified <code>apk_file</code></p>

<p>This opens and parses the contents of the APK&#39;s resources.arsc file.</p>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/apktools/apkresources.rb, line 135</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">apk_file</span>)
  <span class="ruby-identifier">data</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-comment"># Get resources.arsc from the APK file</span>
  <span class="ruby-constant">Zip</span><span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">foreach</span>(<span class="ruby-identifier">apk_file</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/resources.arsc/</span>)
      <span class="ruby-identifier">data</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">get_input_stream</span>.<span class="ruby-identifier">read</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&#39;BINARY&#39;</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Parse the Table Chunk</span>
  <span class="ruby-comment">## Header</span>
  <span class="ruby-identifier">header_type</span> = <span class="ruby-identifier">read_short</span>(<span class="ruby-identifier">data</span>, <span class="ruby-constant">HEADER_START</span>)
  <span class="ruby-identifier">header_size</span> = <span class="ruby-identifier">read_short</span>(<span class="ruby-identifier">data</span>, <span class="ruby-constant">HEADER_START</span><span class="ruby-operator">+</span><span class="ruby-value">2</span>)
  <span class="ruby-identifier">header_chunk_size</span> = <span class="ruby-identifier">read_word</span>(<span class="ruby-identifier">data</span>, <span class="ruby-constant">HEADER_START</span><span class="ruby-operator">+</span><span class="ruby-value">4</span>)
  <span class="ruby-identifier">header_package_count</span> = <span class="ruby-identifier">read_word</span>(<span class="ruby-identifier">data</span>, <span class="ruby-constant">HEADER_START</span><span class="ruby-operator">+</span><span class="ruby-value">8</span>)
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Resource Package Count = #{header_package_count}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>

  <span class="ruby-comment"># Parse the StringPool Chunk</span>
  <span class="ruby-comment">## Header</span>
  <span class="ruby-identifier">startoffset_pool</span> = <span class="ruby-constant">HEADER_START</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">header_size</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Parse Main StringPool Chunk&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>
  <span class="ruby-ivar">@stringpool_main</span> = <span class="ruby-identifier">parse_stringpool</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">startoffset_pool</span>)
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{@stringpool_main.values.length} strings found&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>

  <span class="ruby-comment"># Parse the Package Chunk</span>
  <span class="ruby-comment">## Header</span>
  <span class="ruby-identifier">startoffset_package</span> = <span class="ruby-identifier">startoffset_pool</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@stringpool_main</span>.<span class="ruby-identifier">header</span>.<span class="ruby-identifier">chunk_size</span>
  <span class="ruby-ivar">@packages</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>()
  <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">header_package_count</span>
    <span class="ruby-identifier">package_element</span> = <span class="ruby-identifier">parse_package</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">startoffset_package</span>)
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Package #{package_element.package_header.id}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>
    <span class="ruby-identifier">startoffset_package</span> = <span class="ruby-identifier">startoffset_package</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">package_element</span>.<span class="ruby-identifier">package_header</span>.<span class="ruby-identifier">header</span>.<span class="ruby-identifier">chunk_size</span>
    <span class="ruby-ivar">@packages</span>[<span class="ruby-identifier">package_element</span>.<span class="ruby-identifier">package_header</span>.<span class="ruby-identifier">id</span>] = <span class="ruby-identifier">package_element</span>

    <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">end</span>

<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-get_all_keys" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_all_keys</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Return hash of all the key values in the file keyed by package id</p>
          
          

          
          <div class="method-source-code" id="get_all_keys-source">
            <pre><span class="ruby-comment"># File lib/apktools/apkresources.rb, line 199</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_all_keys</span>
  <span class="ruby-identifier">keys</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>()
  <span class="ruby-ivar">@packages</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">keys</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">stringpool_keystrings</span>.<span class="ruby-identifier">values</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">keys</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-get_all_strings" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_all_strings</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Return array of all string values in the file</p>
          
          

          
          <div class="method-source-code" id="get_all_strings-source">
            <pre><span class="ruby-comment"># File lib/apktools/apkresources.rb, line 178</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_all_strings</span>
  <span class="ruby-keyword">return</span> <span class="ruby-ivar">@stringpool_main</span>.<span class="ruby-identifier">values</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-get_all_types" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_all_types</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Return hash of all the type values in the file keyed by package id</p>
          
          

          
          <div class="method-source-code" id="get_all_types-source">
            <pre><span class="ruby-comment"># File lib/apktools/apkresources.rb, line 186</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_all_types</span>
  <span class="ruby-identifier">types</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>()
  <span class="ruby-ivar">@packages</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">types</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">stringpool_typestrings</span>.<span class="ruby-identifier">values</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">types</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-get_default_resource_value" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_default_resource_value</span><span
            class="method-args">(res_id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Obtain the default value for a given resource id</p>

<p>res_id: ID values of a resources as a FixNum or String representation (i.e.
0x7F060001)</p>

<p>Returns: The default <a
href="ApkResources.html#ResTypeEntry">ResTypeEntry</a> to the given id, or
nil if no default exists</p>
          
          

          
          <div class="method-source-code" id="get_default_resource_value-source">
            <pre><span class="ruby-comment"># File lib/apktools/apkresources.rb, line 261</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_default_resource_value</span>(<span class="ruby-identifier">res_id</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">res_id</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
    <span class="ruby-identifier">res_id</span> = <span class="ruby-identifier">res_id</span>.<span class="ruby-identifier">hex</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">entries</span> = <span class="ruby-identifier">get_resource_value</span>(<span class="ruby-identifier">res_id</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">entries</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">default</span> = <span class="ruby-constant">ResTypeConfig</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>)
    <span class="ruby-identifier">default_entry</span> = <span class="ruby-identifier">entries</span>[<span class="ruby-identifier">default</span>]
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">default_entry</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-get_resource_key" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_resource_key</span><span
            class="method-args">(res_id, xml_format=false)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Obtain the key value for a given resource id</p>

<p>res_id: ID value of a resource as a FixNum or String representation (i.e.
0x7F060001) xml_format: Optionally format return string for XML files.</p>

<p>If xml_format is true, return value will be @&lt;type&gt;/&lt;key&gt; If
xml_format is false or missing, return value will be
R.&lt;type&gt;.&lt;key&gt; If the resource id does not exist, return value
will be nil</p>
          
          

          
          <div class="method-source-code" id="get_resource_key-source">
            <pre><span class="ruby-comment"># File lib/apktools/apkresources.rb, line 218</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_resource_key</span>(<span class="ruby-identifier">res_id</span>, <span class="ruby-identifier">xml_format</span>=<span class="ruby-keyword">false</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">res_id</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
    <span class="ruby-identifier">res_id</span> = <span class="ruby-identifier">res_id</span>.<span class="ruby-identifier">hex</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># R.id integers are a concatenation of package_id, type_id, and entry index</span>
  <span class="ruby-identifier">res_package</span> = (<span class="ruby-identifier">res_id</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xFF</span>
  <span class="ruby-identifier">res_type</span> = (<span class="ruby-identifier">res_id</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xFF</span>
  <span class="ruby-identifier">res_index</span> = <span class="ruby-identifier">res_id</span> <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xFFFF</span>

  <span class="ruby-identifier">package_element</span> = <span class="ruby-ivar">@packages</span>[<span class="ruby-identifier">res_package</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">package_element</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-comment"># This is not a resource we can parse</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">res_spec</span> = <span class="ruby-identifier">package_element</span>.<span class="ruby-identifier">type_data</span>[<span class="ruby-identifier">res_type</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">res_spec</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Could not find ResTypeSpec for #{res_package} #{res_type}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">entry</span> = <span class="ruby-identifier">res_spec</span>.<span class="ruby-identifier">types</span>.<span class="ruby-identifier">entries</span>[<span class="ruby-identifier">res_index</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">entry</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-comment"># There is no entry in our table for this resource</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Could not find #{res_spec.types.id} ResType chunk&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">xml_format</span>
    <span class="ruby-keyword">return</span> <span class="ruby-node">&quot;@#{res_spec.id}/#{entry.values[0].key}&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-node">&quot;R.#{res_spec.id}.#{entry.values[0].key}&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-get_resource_value" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_resource_value</span><span
            class="method-args">(res_id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Obtain the value(s) for a given resource id. A default resource is one
defined in an unqualified directory.</p>

<p>res_id: ID value of a resource as a FixNum or String representation (i.e.
0x7F060001)</p>

<p>Returns: Hash of all entries matching this id, keyed by their matching <a
href="ApkResources.html#ResTypeConfig">ResTypeConfig</a> or nil if the
resource id cannot be found.</p>
          
          

          
          <div class="method-source-code" id="get_resource_value-source">
            <pre><span class="ruby-comment"># File lib/apktools/apkresources.rb, line 285</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_resource_value</span>(<span class="ruby-identifier">res_id</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">res_id</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
    <span class="ruby-identifier">res_id</span> = <span class="ruby-identifier">res_id</span>.<span class="ruby-identifier">hex</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># R.id integers are a concatenation of package_id, type_id, and entry index</span>
  <span class="ruby-identifier">res_package</span> = (<span class="ruby-identifier">res_id</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xFF</span>
  <span class="ruby-identifier">res_type</span> = (<span class="ruby-identifier">res_id</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xFF</span>
  <span class="ruby-identifier">res_index</span> = <span class="ruby-identifier">res_id</span> <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xFFFF</span>

  <span class="ruby-identifier">package_element</span> = <span class="ruby-ivar">@packages</span>[<span class="ruby-identifier">res_package</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">package_element</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-comment"># This is not a resource we can parse</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">res_spec</span> = <span class="ruby-identifier">package_element</span>.<span class="ruby-identifier">type_data</span>[<span class="ruby-identifier">res_type</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">res_spec</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Could not find ResTypeSpec for #{res_package} #{res_type}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">entries</span> = <span class="ruby-identifier">res_spec</span>.<span class="ruby-identifier">types</span>.<span class="ruby-identifier">entries</span>[<span class="ruby-identifier">res_index</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">entries</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Could not find #{res_spec.types.id} ResType chunk&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">DEBUG</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">entries</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.0.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

